From: Ben Hutchings Date: Thu, 10 Dec 2015 18:02:48 +0000 (+0000) Subject: cgroups: Allow memory cgroup support to be included but disabled X-Git-Tag: archive/raspbian/4.9.13-1+rpi1~117 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/%22mailto:kde%40ewsoftware.de//%22style.css/%22/%22http:/www.example.com/%22mailto:kde%40ewsoftware.de/%22style.css/%22?a=commitdiff_plain;h=0a175472568946052ed16468e8b1261d0b731b8c;p=linux-4.9.git cgroups: Allow memory cgroup support to be included but disabled Memory cgroup support has some run-time overhead, so it's useful to include it in a distribution kernel without enabling it by default. Add a kernel config option to disable it by default and a kernel parameter 'cgroup_enable' as the opposite to 'cgroup_disable'. Signed-off-by: Ben Hutchings [Bastian Blank: Rename CGROUP_MEM_RES_CTLR_DISABLED to MEMCG_DISABLED] Gbp-Pq: Topic features/all Gbp-Pq: Name cgroups-Allow-memory-cgroup-support-to-be-included-b.patch --- diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt index 742f69d18fc8..30690908c6c8 100644 --- a/Documentation/kernel-parameters.txt +++ b/Documentation/kernel-parameters.txt @@ -588,8 +588,8 @@ bytes respectively. Such letter suffixes can also be entirely omitted. ccw_timeout_log [S390] See Documentation/s390/CommonIO for details. - cgroup_disable= [KNL] Disable a particular controller - Format: {name of the controller(s) to disable} + cgroup_disable= [KNL] Disable/enable a particular controller + cgroup_enable= Format: {name of the controller(s) to disable/enable} The effects of cgroup_disable=foo are: - foo isn't auto-mounted if you mount all cgroups in a single hierarchy diff --git a/init/Kconfig b/init/Kconfig index 235c7a2c0d20..d3999071dd4b 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1010,6 +1010,14 @@ config MEMCG Provides a memory resource controller that manages both anonymous memory and page cache. (See Documentation/cgroups/memory.txt) +config MEMCG_DISABLED + bool "Memory Resource Controller disabled by default" + depends on MEMCG + default n + help + Disable the memory group resource controller unless explicitly + enabled using the kernel parameter "cgroup_enable=memory". + config MEMCG_SWAP bool "Memory Resource Controller Swap Extension" depends on MEMCG && SWAP diff --git a/kernel/cgroup.c b/kernel/cgroup.c index fb1ecfd2decd..8ffdbc1d94e8 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -5286,7 +5286,11 @@ int __init cgroup_init_early(void) return 0; } +#ifdef CONFIG_MEMCG_DISABLED +static unsigned long cgroup_disable_mask __initdata = 1 << memory_cgrp_id; +#else static unsigned long cgroup_disable_mask __initdata; +#endif /** * cgroup_init - cgroup initialization @@ -5761,7 +5765,7 @@ out_free: kfree(pathbuf); } -static int __init cgroup_disable(char *str) +static int __init cgroup_set_disabled(char *str, int value) { struct cgroup_subsys *ss; char *token; @@ -5775,13 +5779,27 @@ static int __init cgroup_disable(char *str) if (strcmp(token, ss->name) && strcmp(token, ss->legacy_name)) continue; - cgroup_disable_mask |= 1 << i; + if (value) + cgroup_disable_mask |= 1 << i; + else + cgroup_disable_mask &= ~(1 << i); } } return 1; } + +static int __init cgroup_disable(char *str) +{ + return cgroup_set_disabled(str, 1); +} __setup("cgroup_disable=", cgroup_disable); +static int __init cgroup_enable(char *str) +{ + return cgroup_set_disabled(str, 0); +} +__setup("cgroup_enable=", cgroup_enable); + /** * css_tryget_online_from_dir - get corresponding css from a cgroup dentry * @dentry: directory dentry of interest